import com.alibaba.fastjson.JSON;
import redis.clients.jedis.Jedis;

public class Demo1 {
    private static void put(Post post){
        Jedis jedis = new Jedis("127.0.0.1",6379);
        Long id = jedis.incr("posts:count");
        String key = "post:" + id + ":data";
        String strPost = JSON.toJSONString(post);
        jedis.set(key,strPost);
    }


    private static Post get(Long id){
        Jedis jedis = new Jedis("127.0.0.1",6379);
        String key = "post:" + id + ":data";
        String strPost = jedis.get(key);
        Post post  = JSON.parseObject(strPost,Post.class);
        String key2 = "post:" + id + ":page.view";
        Long count = jedis.incr(key2);
        return post;
    }
}
